<?php
declare(strict_types=1);

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Support\JsExp;
use LowCode\Traits\Props\HasBordered;
use LowCode\Traits\Props\HasCircle;
use LowCode\Traits\Props\HasDisabled;
use LowCode\Traits\Props\HasLoading;
use LowCode\Traits\Props\HasRound;
use LowCode\Traits\Props\HasTag;
use LowCode\Traits\Props\HasTinySize;
use LowCode\Traits\Props\HasType;
use LowCode\Traits\Slots\HasSlotIcon;
use LowCode\UI\SvgIcon;

/**
 * 按钮组件 NButton
 * @method static Button make(mixed $children = null) Button 按钮组件
 */
class Button extends Naive
{

    use HasTag, HasTinySize, HasType, HasLoading, HasDisabled, HasBordered, HasRound, HasCircle;

    use HasSlotIcon;

    /**
     * @param mixed $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        if ($children instanceof SvgIcon){
            $this->slotIcon($children);
        }else{
            $this->children($children);
        }
    }

    /**
     * 按钮类型
     * @param string|JsExp $type 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
     * @return $this
     */
    public function type(string|JsExp $type = 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'): static
    {
        return $this->prop('type',$type);
    }

    /**
     * 默认按钮类型
     * @return $this
     */
    public function default(): static
    {
        return $this->type('default');
    }

    /**
     * 是否是二级按钮
     * @param bool|JsExp $bool
     * @return $this
     */
    public function secondary(bool|JsExp $bool = true): static
    {
        return $this->prop('secondary', $bool);
    }

    /**
     * 是否是三级按钮
     * @param bool|JsExp $bool 设置tertiary=$bool
     * @return $this
     */
    public function tertiary(bool|JsExp $bool = true): static
    {
        return $this->prop('tertiary',$bool);
    }

    /**
     * 是否是四级按钮
     * @param bool|JsExp $bool
     * @return $this
     */
    public function quaternary(bool|JsExp $bool = true): static
    {
        return $this->prop('quaternary', $bool);
    }


    /**
     * 按钮是否显示为块级
     * @param bool|JsExp $bool
     * @return $this
     */
    public function block(bool|JsExp $bool = true): static
    {
        return $this->prop('block', $bool);
    }


    /**
     * 设置按钮背景颜色
     * @param string|JsExp $color
     * @return $this
     */
    public function color(string|JsExp $color = ''): static
    {
        return $this->prop('color', $color);
    }

    /**
     * 是否为虚线
     * @param bool|JsExp $bool
     * @return $this
     */
    public function dashed(bool|JsExp $bool = true): static
    {
        return $this->prop('dashed', $bool);
    }


    /**
     * 按钮是否可以被聚焦
     * @param bool|JsExp $bool
     * @return $this
     */
    public function focusable(bool|JsExp $bool = true): static
    {
        return $this->prop('focusable', $bool);
    }

    /**
     * 按钮是否透明
     * @param bool|JsExp $bool
     * @return $this
     */
    public function ghost(bool|JsExp $bool = true): static
    {
        return $this->prop('ghost', $bool);
    }

    /**
     * 是否支持键盘操作
     * @param bool|JsExp $bool
     * @return $this
     */
    public function keyboard(bool|JsExp $bool = true): static
    {
        return $this->prop('keyboard', $bool);
    }


    /**
     * 按钮是否加粗
     * @param bool|JsExp $bool
     * @return $this
     */
    public function strong(bool|JsExp $bool = true): static
    {
        return $this->prop('strong', $bool);
    }

    /**
     * 是否显示为文本按钮
     * @param bool|JsExp $bool
     * @return $this
     */
    public function text(bool|JsExp $bool = true): static
    {
        return $this->prop('text', $bool);
    }

    /**
     * 按钮文字颜色
     * @param string|JsExp $color
     *
     * @return $this
     */
    public function textColor(string|JsExp $color = ''): static
    {
        return $this->prop('textColor', $color);
    }

    /**
     * 按钮中图标的位置
     * @param string|JsExp $iconPlacement 'left' | 'right'
     * @return $this
     */
    public function iconPlacement(string|JsExp $iconPlacement = 'left' | 'right'): static
    {
        return $this->prop('iconPlacement', $iconPlacement);
    }

    /**
     * 按钮文字颜色
     * @param string $value () => VNodeChild
     * @param string|null $id
     * @return $this
     */
    public function renderIcon(string $value = '', string $id = null): static
    {
        return $this->jsFunction('render-icon', $value, $id);
    }

    /**
     * 按钮的 DOM 的 type 属性
     * @param string|JsExp $attrType 'button' | 'submit' | 'reset'
     * @return $this
     */
    public function attrType(string|JsExp $attrType = 'button' | 'submit' | 'reset'): static
    {
        return $this->prop('attrType', $attrType);
    }

}
